using System;
using System.Collections.Generic;
using System.Text;


namespace Lizk.SimpleHUD
{
    public class HUDImageBox : HUDContainerSimple
    {
        private HUDImage image1, image2, currentImage;
        private string defaultImage;

        private float fadeSpeed = 6f;

        public float FadeSpeed
        {
            get { return fadeSpeed; }
            set { fadeSpeed = value; }
        }

        public HUDImageBox()
        {
            image1 = new HUDImage(null);
            image1.Alpha = 255;
            image1.Bounds = Bounds;
            image1.Anchor = Anchor.All;
            this.Add(image1);

            image2 = new HUDImage(null);
            image2.Alpha = 0;
            image2.Bounds = Bounds;
            image2.Anchor = Anchor.All;
            this.Add(image2);

            currentImage = image1;
        }

        public string CurrentImage
        {
            get { 
                if(currentImage.File == defaultImage)
                    return null;
                if (currentImage.File == null)
                    return null;
                return currentImage.File;
            }
            set
            {
                if (value == CurrentImage)
                    return;
                currentImage.Fade(0, fadeSpeed);

                currentImage = currentImage == image1 ? image2 : image1;
                if (value != null)
                {
                    currentImage.File = value;
                }
                else
                {
                    currentImage.File = defaultImage;
                }
                SwitchImage(null, null);

            }
        }

        public string DefaultImage
        {
            get { return defaultImage; }
            set
            {
                defaultImage = value;
                if(CurrentImage == null)
                    currentImage.File = value;
            }
        }

        private void SwitchImage(object sender, EventArgs ea)
        {
            currentImage.Fade(255, fadeSpeed);            
        }
    }


}
